#include <stdio.h>
#include "drawingEvent.h"

DrawingEvent::DrawingEvent(DrawingEventType d_evt_type) : Event()
{
	member_value("type", (PortableInteger)DRAWING_EVENT_TYPE);
	member_value("drawing_event_type", (PortableInteger)d_evt_type);
	member_value("color", "0x000000");
}

DrawingEvent::~DrawingEvent()
{
	
}

int DrawingEvent::get_subtype()
{
	PortableInteger integer;
	GenericObject obj = member_value("drawing_event_type");
	obj >>= integer;
	
	return (int)integer;
}

const char* DrawingEvent::color()
{
	GenericObject obj = member_value("color");
	const char* color;
	obj >>= color;
	
	return color;
}

void DrawingEvent::color(const char* c)
{
	member_value("color", c);
}

LineEvent::LineEvent(float x0, float y0, float x1, float y1)
 : DrawingEvent(LINE)
{
	member_value("x0", (PortableFloat)x0);
	member_value("y0", (PortableFloat)y0);
	member_value("x1", (PortableFloat)x1);
	member_value("y1", (PortableFloat)y1);
}

float LineEvent::x0()
{
	GenericObject obj = member_value("x0");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float LineEvent::y0()
{
	GenericObject obj = member_value("y0");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float LineEvent::x1()
{
	GenericObject obj = member_value("x1");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float LineEvent::y1()
{
	GenericObject obj = member_value("y1");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

RectangleEvent::RectangleEvent(float x, float y, float width, float height)
 : DrawingEvent(RECTANGLE)
{
	member_value("x", (PortableFloat)x);
	member_value("y", (PortableFloat)y);
	member_value("width", (PortableFloat)width);
	member_value("heigth", (PortableFloat)height);
}

float RectangleEvent::x()
{
	GenericObject obj = member_value("x");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float RectangleEvent::y()
{
	GenericObject obj = member_value("y");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float RectangleEvent::width()
{
	GenericObject obj = member_value("width");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float RectangleEvent::height()
{
	GenericObject obj = member_value("heigth");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

FilledRectangleEvent::FilledRectangleEvent(float x, float y, float width, float height)
 : RectangleEvent(x, y, width, height)
{
	member_value("fill_color", "0xffffff");
	member_value("drawing_event_type", (PortableInteger)FILLED_RECTANGLE);
}

const char* FilledRectangleEvent::fill_color()
{
	GenericObject obj = member_value("fill_color");
	const char* color;
	obj >>= color;
	
	return color;
}

void FilledRectangleEvent::fill_color(const char* c)
{
	member_value("fill_color", c);
}

EllipseEvent::EllipseEvent(float x, float y, float width, float height)
 : DrawingEvent(ELLIPSE)
{
	member_value("x", (PortableFloat)x);
	member_value("y", (PortableFloat)y);
	member_value("width", (PortableFloat)width);
	member_value("heigth", (PortableFloat)height);
}

float EllipseEvent::x()
{
	GenericObject obj = member_value("x");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float EllipseEvent::y()
{
	GenericObject obj = member_value("y");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float EllipseEvent::width()
{
	GenericObject obj = member_value("width");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float EllipseEvent::height()
{
	GenericObject obj = member_value("height");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

FilledEllipseEvent::FilledEllipseEvent(float x, float y, float width, float height)
 : EllipseEvent(x, y, width, height)
{
	member_value("fill_color", "0xffffff");
	member_value("drawing_event_type", (PortableInteger)FILLED_ELLIPSE);
}

const char* FilledEllipseEvent::fill_color()
{
	GenericObject obj = member_value("fill_color");
	const char* color;
	obj >>= color;
	
	return color;
}

void FilledEllipseEvent::fill_color(const char* c)
{
	member_value("fill_color", c);
}

CircleEvent::CircleEvent(float x, float y, float radius)
 : DrawingEvent(CIRCLE)
{
	member_value("x", (PortableFloat)x);
	member_value("y", (PortableFloat)y);
	member_value("radius", (PortableFloat)radius);
}

float CircleEvent::x()
{
	GenericObject obj = member_value("x");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float CircleEvent::y()
{
	GenericObject obj = member_value("y");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float CircleEvent::radius()
{
	GenericObject obj = member_value("radius");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

FilledCircleEvent::FilledCircleEvent(float x, float y, float radius)
 : CircleEvent(x, y, radius)
{
	member_value("fill_color", "0xffffff");
	member_value("drawing_event_type", (PortableInteger)FILLED_CIRCLE);
}

const char* FilledCircleEvent::fill_color()
{
	GenericObject obj = member_value("fill_color");
	const char* color;
	obj >>= color;
	
	return color;
}

void FilledCircleEvent::fill_color(const char* c)
{
	member_value("fill_color", c);
}

TriangleEvent::TriangleEvent(float x0, float y0, float x1, float y1, float x2, float y2)
 : DrawingEvent(TRIANGLE)
{
	member_value("x0", (PortableFloat)x0);
	member_value("y0", (PortableFloat)y0);
	member_value("x1", (PortableFloat)x1);
	member_value("y1", (PortableFloat)y1);
	member_value("x2", (PortableFloat)x2);
	member_value("y2", (PortableFloat)y2);
}

float TriangleEvent::x0()
{
	GenericObject obj = member_value("x0");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float TriangleEvent::y0()
{
	GenericObject obj = member_value("y0");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float TriangleEvent::x1()
{
	GenericObject obj = member_value("x1");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float TriangleEvent::y1()
{
	GenericObject obj = member_value("y1");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float TriangleEvent::x2()
{
	GenericObject obj = member_value("x2");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float TriangleEvent::y2()
{
	GenericObject obj = member_value("y2");
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

FilledTriangleEvent::FilledTriangleEvent(float x0, float y0, float x1, float y1, float x2, float y2)
 : TriangleEvent(x0,y0,x1,y1,x2,y2)
{
	member_value("fill_color", "0xffffff");
	member_value("drawing_event_type", (PortableInteger)FILLED_TRIANGLE);
}

const char* FilledTriangleEvent::fill_color()
{
	GenericObject obj = member_value("fill_color");
	const char* color;
	obj >>= color;
	
	return color;
}

void FilledTriangleEvent::fill_color(const char* c)
{
	member_value("fill_color", c);	
}

HandDrawEvent::HandDrawEvent(int npoints)
 : DrawingEvent(HAND_DRAW)
{
	char x_str[50];
	char y_str[50];
	for (int i=0; i<npoints; i++)
	{
		sprintf(x_str, "x%d", i);
		sprintf(y_str, "y%d", i);
		member_value(x_str, (PortableFloat)0);
		member_value(y_str, (PortableFloat)0);
	}
	
	member_value("npoints", (PortableInteger)npoints);
}

int HandDrawEvent::npoints()
{
	GenericObject obj = member_value("npoints");
	PortableInteger x;
	obj >>= x;
	
	return (int)x;
}

float HandDrawEvent::xn(int n)
{
	char x_str[50];
	sprintf(x_str, "x%d", n);
	
	GenericObject obj = member_value(x_str);
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

float HandDrawEvent::yn(int n)
{
	char y_str[50];
	sprintf(y_str, "y%d", n);
	
	GenericObject obj = member_value(y_str);
	PortableFloat x;
	obj >>= x;
	
	return (float)x;
}

void HandDrawEvent::xn(int n, float f)
{
	if (n >= 0)
	{
		char str[50];
		sprintf(str, "x%d", n);
		
		member_value(str, (PortableFloat)f);
	}
}

void HandDrawEvent::yn(int n, float f)
{
	if (n >= 0)
	{
		char str[50];
		sprintf(str, "y%d", n);
		
		member_value(str, (PortableFloat)f);
	}
}

